package com.digitalchina.lxnsy.viewholder;

import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.entity.ExpertNewVO;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.facebook.drawee.view.SimpleDraweeView;
import com.hedgehog.ratingbar.RatingBar;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;

import java.text.MessageFormat;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.viewholder
 * 创建人：白彦东
 * 创建时间：2016/12/28 18:10
 * 修改备注：2017/3/26 14:00:38 郑皓修改
 * ================================================
 */

public class ExpertListHolder extends BaseViewHolder<ExpertNewVO> {

    private SimpleDraweeView ivImage;//头像
    private LinearLayout selectCheck;
    private ImageView chooseImage; //选择后图片
    private TextView tvExpertName;//姓名
    private TextView tvExpertTitle;//职称
    private TextView tvExpertArea;//涉及领域
    private RatingBar barScore;//评分

    private TextView tvAskNum;  // 提问量
    private TextView tvReplyNum; // 回复量
    private TextView tvStudentNum; // 学员数
//    private TextView tvExpertProvince;
//    private TextView tvExpertUniverse;
//    private ImageView ivExpertContact;
//    private ImageView ivIsChat; // 是否为签约专家标志


    public ExpertListHolder(ViewGroup parent) {
        super(parent, R.layout.item_experts_list);
        ivImage = $(R.id.item_iv_expert_iv_avatar);
        tvExpertName = $(R.id.item_expert_list_tv_name);
        tvExpertTitle = $(R.id.item_expert_list_tv_titles);
        tvExpertArea = $(R.id.item_expert_list_tv_area);
        barScore = $(R.id.item_expert_list_bar_score);

        tvAskNum = $(R.id.item_expert_list_tv_ask_num);
        tvReplyNum = $(R.id.item_expert_list_tv_reply_num);
        tvStudentNum = $(R.id.item_expert_list_tv_student_num);
        selectCheck = $(R.id.select_check);
        chooseImage = $(R.id.choose_image);

//        tvExpertUniverse = $(R.id.item_tv_expert_universe_name);
//        ivIsChat = $(R.id.item_iv_expert_is_chat);
//        super(parent, R.layout.item_agricultural_experts);
//        ivImage = $(R.id.item_iv_expert_avatar);
//        ivExpertContact = $(R.id.item_iv_expert_contact);
//        tvExpertName = $(R.id.item_tv_expert_name);
//        tvExpertTitle = $(R.id.item_tv_expert_titles);
//        tvExpertProvince = $(R.id.item_tv_expert_province);
//        tvExpertUniverse = $(R.id.item_tv_expert_universe_name);
//        ivIsChat = $(R.id.item_iv_expert_is_chat);
    }

    @Override
    public void setData(final ExpertNewVO data) {
        super.setData(data);


        tvAskNum.setText(MessageFormat.format("提问量：{0}", StringUtil.isStrEmpty(data.getQuestionNUm()) ? "0" : data.getQuestionNUm()));
        tvReplyNum.setText(MessageFormat.format("回复量：{0}", StringUtil.isStrEmpty(data.getAnswerNum()) ? "0" : data.getAnswerNum()));
        tvStudentNum.setText(MessageFormat.format("学员数：{0}", StringUtil.isStrEmpty(data.getStudentNum()) ? "0" : data.getStudentNum()));


        FrescoUtil.showImageSmall(data.getPhoto() != null ? data.getPhoto() : "", ivImage);

        tvExpertName.setText(!StringUtil.isStrEmpty(data.getExpertName()) ? data.getExpertName() : "匿名专家");

//        if (!TextUtils.isEmpty(data.getExpertSex())) {
//            if (data.getExpertSex().equals("男")) {
//                isMale();
//            } else {
//                isFemale();
//            }
//        }
        if (data.getExpertTitle() == null || StringUtil.isStrEmpty(data.getExpertTitle().getTitle())) {
            tvExpertTitle.setVisibility(View.GONE);
        } else {
            tvExpertTitle.setVisibility(View.VISIBLE);
            tvExpertTitle.setText(data.getExpertTitle().getTitle());
        }
        tvExpertArea.setText(data.getExpertClassification() != null ? data.getExpertClassification().getPname() + "  " + data.getExpertClassification().getName() : "");
        barScore.setStar((float) data.getScore());

//        tvExpertProvince.setText(data.getAddress() != null ? data.getAddress() : "");
//        tvExpertUniverse.setText(data.getWorkUnit() != null ? data.getWorkUnit() : "");
//
//        if (data.getIsChat() != null && data.getIsChat().equals("1"))
//            ivIsChat.setVisibility(View.VISIBLE);
//        else
//            ivIsChat.setVisibility(View.GONE);
//
//
//        ivExpertContact.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                //启动会话界面
//                if (RongIM.getInstance() != null)
//                    RongIM.getInstance().startPrivateChat(getContext(), data.getId(), data.getExpertName());
//            }
//        });
    }

    private void isMale() {
        Drawable drawable = getContext().getResources().getDrawable(R.drawable.icon_male);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tvExpertName.setCompoundDrawables(drawable, null, null, null);
    }

    private void isFemale() {
        Drawable drawable = getContext().getResources().getDrawable(R.drawable.icon_female);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        tvExpertName.setCompoundDrawables(drawable, null, null, null);
    }
}
